package com.huaxia.service.realAct;

import com.huaxia.dao.realAct.*;
import com.huaxia.pojo.realAct.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.List;

/**
 * @author wangli 爱我华夏，爱我中华！
 * @date 2020/06/08 16:37
 */
@Service
public class RealActService {

    @Autowired
    private BranchMonthActMapper branchMonthActMapper;
    @Autowired
    private BranchClassActMapper branchClassActMapper;
    @Autowired
    private BranchBcActMapper branchBcActMapper;
    @Autowired
    private BranchBmActMapper branchBmActMapper;

    @Autowired
    private SaleDeptMonthActMapper saleDeptMonthActMapper;
    @Autowired
    private SaleDeptClassActMapper saleDeptClassActMapper;
    @Autowired
    private SaleDeptBcActMapper saleDeptBcActMapper;
    @Autowired
    private SaleDeptBmActMapper saleDeptBmActMapper;

    @Autowired
    private SzMonthActMapper szMonthActMapper;

    public List<BranchMonthAct> getBranchThisMonthAct() {

        Calendar calendar = Calendar.getInstance();
        int today = calendar.get(Calendar.DAY_OF_MONTH);



        List<Month10000> monAdd10000List = null;
        if (today <= 1) {
            monAdd10000List = branchMonthActMapper.findMonAdd10000_1();
        }
        if (today > 1 && today < 16) {
            monAdd10000List = branchMonthActMapper.findMonAdd10000_before15_includeToday();
            List<Month10000> before15none = branchMonthActMapper.findMonAdd10000_before15_noneToday();
            for (Month10000 month10000 : monAdd10000List) {
                for (Month10000 monthAdd : before15none) {
                    if (month10000.getBranchsName().equals(monthAdd.getBranchsName())) {
                        month10000.setMonAdd10000(month10000.getMonAdd10000()-monthAdd.getMonAdd10000());
                        break;
                    }
                }
            }
        }
        if (today >= 16) {
            monAdd10000List = branchMonthActMapper.findMonAdd10000_after15_includeToday();
            List<Month10000> after15none = branchMonthActMapper.findMonAdd10000_after15_noneToday();
            for (Month10000 month10000 : monAdd10000List) {
                for (Month10000 monthAdd : after15none) {
                    if (month10000.getBranchsName().equals(monthAdd.getBranchsName())) {
                        month10000.setMonAdd10000(month10000.getMonAdd10000()-monthAdd.getMonAdd10000());
                        break;
                    }
                }
            }
        }
        List<BranchMonthAct> monthActList = branchMonthActMapper.getBranchThisMonthAct();
        for (BranchMonthAct branchMonthAct : monthActList) {
            for (Month10000 month10000 : monAdd10000List) {
                if (month10000.getBranchsName().equals(branchMonthAct.getBranchsName())) {
                    branchMonthAct.setMonAdd10000(month10000.getMonAdd10000());
                    break;
                }
            }
        }

        return monthActList;
    }

    public List<BranchMonthAct> getBranchNextMonthAct() {

        Calendar calendar = Calendar.getInstance();
        int today = calendar.get(Calendar.DAY_OF_MONTH);



        List<Month10000> monAdd10000List = branchMonthActMapper.findNextMonAdd10000_includeToday();

        if (today > 1) {
            List<Month10000> noneToday = branchMonthActMapper.findNextMonAdd10000_noneToday();
            for (Month10000 month10000 : monAdd10000List) {
                for (Month10000 monthAdd : noneToday) {
                    if (month10000.getBranchsName().equals(monthAdd.getBranchsName())) {
                        month10000.setMonAdd10000(month10000.getMonAdd10000()-monthAdd.getMonAdd10000());
                        break;
                    }
                }
            }
        }

        List<BranchMonthAct> monthActList = branchMonthActMapper.getBranchNextMonthAct();
        for (BranchMonthAct branchMonthAct : monthActList) {
            for (Month10000 month10000 : monAdd10000List) {
                if (month10000.getBranchsName().equals(branchMonthAct.getBranchsName())) {
                    branchMonthAct.setMonAdd10000(month10000.getMonAdd10000());
                    break;
                }
            }
        }

        return monthActList;
    }

    public List<BranchClassAct> getBranchClassAct() {

        return branchClassActMapper.getBranchClassAct();
    }

    public List<BranchBcAct> getBranchBcAct() {

        return branchBcActMapper.getBranchBcAct();
    }

    public List<BranchBmAct> getBranchBmAct() {

        return branchBmActMapper.getBranchBmAct();
    }


    public List<SaleDeptMonthAct> getSaleDeptMonthAct() {

        return saleDeptMonthActMapper.getSaleDeptMonthAct();
    }

    public List<SaleDeptClassAct> getSaleDeptClassAct() {

        return saleDeptClassActMapper.getSaleDeptClassAct();
    }

    public List<SaleDeptBcAct> getSaleDeptBcAct() {

        return saleDeptBcActMapper.getSaleDeptBcAct();
    }

    public List<SaleDeptBmAct> getSaleDeptBmAct() {

        return saleDeptBmActMapper.getSaleDeptBmAct();
    }

    public List<SzMonthAct> getSzMonthAct() {

        return szMonthActMapper.getSzMonthAct();
    }
}
